package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);


    Page<SetmealDTO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

//插入套餐信息
    @AutoFill(value = OperationType.INSERT)
//    @Insert("insert into setmeal (" +
//            "id, category_id, name, price, status, " +
//            "description, image, create_time, update_time, " +
//            "create_user, update_user" +
//            ") VALUES (" +
//            "#{id}, #{categoryId}, #{name}, #{price}, #{status}, " +
//            "#{description}, #{image}, #{createTime}, #{updateTime}, " +
//            "#{createUser}, #{updateUser}" +
//            ")")
    void insert(Setmeal setmeal);
    //插入关联表
@AutoFill(value = OperationType.INSERT)
@Insert("insert into setmeal_dish (id,setmeal_id,dish_id,name,price,copies)"+"values (#{id},#{setmealId},#{dishId},#{name},#{price},#{copies})")
    void insertSetmealWithDish(SetmealDish setmealDish);

//查询套餐状态
    @Select("select status from setmeal where id= #{id}")
    Integer getStatusByid(Long id);

    @Delete("delete from setmeal where id =#{id}")
    void deleteById(Long setmealId);
    @Delete("delete from setmeal_dish where setmeal_id= #{setmealId}")
    void setmealDish(Long setmealId);

    @Select("select * from setmeal where id =#{id}")
    Setmeal getById(Long id);
@AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);
//查询与套餐关联的菜品
@Select("select * from setmeal_dish where id= #{id}")
    List<SetmealDish> getDishById(Long id);

    List<Setmeal> list(Setmeal setmeal);

    List<DishItemVO> getDishItemBySetmealId(Long id);
}
